package com.trex.modules.tbl.carfault.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.trex.modules.tbl.carfault.entity.TblXdClgz;
import com.trex.modules.tbl.carfault.service.TblXdClgzService;

/**
 * 车辆故障表Controller
 * @author jy
 * @version 2023-11-13
 */
@Controller
@RequestMapping(value = "${adminPath}/tbl/carfault/tblXdClgz")
public class TblXdClgzController extends BaseController {

	@Autowired
	private TblXdClgzService tblXdClgzService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TblXdClgz get(String recId, boolean isNewRecord) {
		return tblXdClgzService.get(recId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	//@RequiresPermissions("tbl:carfault:tblXdClgz:view")
	@RequestMapping(value = {"list", ""})
	public String list(TblXdClgz tblXdClgz, Model model) {
		model.addAttribute("tblXdClgz", tblXdClgz);
		return "modules/tbl/carfault/tblXdClgzList";
	}
	
	/**
	 * 查询列表数据
	 */
	//@RequiresPermissions("tbl:carfault:tblXdClgz:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TblXdClgz> listData(TblXdClgz tblXdClgz, HttpServletRequest request, HttpServletResponse response) {
		tblXdClgz.setPage(new Page<>(request, response));
		Page<TblXdClgz> page = tblXdClgzService.findPage(tblXdClgz);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("tbl:carfault:tblXdClgz:view")
	@RequestMapping(value = "form")
	public String form(TblXdClgz tblXdClgz, Model model) {
		model.addAttribute("tblXdClgz", tblXdClgz);
		return "modules/tbl/carfault/tblXdClgzForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("tbl:carfault:tblXdClgz:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TblXdClgz tblXdClgz) {
		tblXdClgzService.save(tblXdClgz);
		return renderResult(Global.TRUE, text("保存车辆故障表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("tbl:carfault:tblXdClgz:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TblXdClgz tblXdClgz) {
		tblXdClgzService.delete(tblXdClgz);
		return renderResult(Global.TRUE, text("删除车辆故障表成功！"));
	}
	
}